package praktikumid.w05.p2;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * Code from 01.10.2013 (week 5, tuesday 0800).
 * Note: this code fails with cehckstyle. 
 * It's just a quick and dirty example.
 * Check example from w05.p5 package
 * for properly commented code.
 * @author Ago
 *
 */
public class Arguments {

	public static void main(String[] args) throws ParseException {

		//String[] arguments = new String[]{"-u", "ago", "luberg"};
		//args = arguments;
		if (args.length == 0) {
			help();
		}
		
		String name = "";
		boolean uppercase = false;
		
		for (int i = 0; i < args.length; i++) {
			if (args[i].charAt(0) == '-') {
				// option
				if (args[i].equals("-u")) {
					uppercase = true;
				} else {
					System.out.println("unknown argument " + args[i]);
					help();
				}
			} else {
				name += args[i] + " ";
			}
		}
		if (uppercase) {
			name = name.toUpperCase();
		}
		
		System.out.println("Tere " + name);
		
		Locale.setDefault(Locale.US);
		// dates
		
		// 2013-09-12T12:55:12.123Z
		
		String dateString = "Thu 01.08.2013 8:29:19,85";
		SimpleDateFormat sdf = new SimpleDateFormat("E dd.MM.yyyy HH:mm:ss,SS");
		Date d1 = sdf.parse(dateString);
		
		System.out.println(d1);
		
		Calendar cal1 = Calendar.getInstance();
		cal1.setTime(d1);
		
		Calendar cal3 = (Calendar) cal1.clone();
		
		cal1.add(Calendar.DAY_OF_MONTH, -3);
		Date d2 = cal1.getTime();
		System.out.println(d2);
		
		cal3.add(Calendar.DAY_OF_MONTH, 3);
		Date d3 = cal3.getTime();
		System.out.println(d3);
		
		Calendar cal2 = Calendar.getInstance();
		cal2.add(Calendar.HOUR, 40);
		System.out.println(cal2.getTime());
		
		if (cal1.before(cal3)) {
			System.out.println("cal1 < cal3");
		}
		if (d2.before(d3)) {
			System.out.println("d2 < d3");
		}
		
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		System.out.println(sdf2.format(d1));
		
		/*
		 * 
		 * panoramio
		 * 
		 * 5p
		 * 
		 * read location from arguments
		 * request to google maps using location
		 * parse response from google maps
		 * check the coordinates
		 * request to panoramio using coordinates
		 * parse response from panoramio to an object
		 * print out
		 * 
		 * 3p - cache
		 * 
		 * read cache arguments
		 * read cache file
		 * gmaps request, response
		 * panoramio request, response
		 * 
		 * compare cache and response
		 * 
		 * write cache file
		 * 
		 * print out
		 * 
		 * 2p - sort
		 * 
		 * read sort arguments
		 * store objects in an array
		 * sort array
		 * reverse sort
		 * 
		 * 
		 * CACHE
		 * SORT
		 * 
		 */
	}

	public static void help() {
		System.out.println("Usage: java -jar program.jar [OPTIONS] name");
		System.out.println("options:");
		System.out.println("       -u	print name in uppercase");
		
		System.exit(13);
	}
}
